﻿@{
    Layout = "~/Views/Shared/_LayoutForEUI.cshtml";
    var listColumns = ViewBag.Columns as List<SGArchiveSystem7x.Models.CColumnsModel>;
}
<table id="ArchiveAuthority_DepartmentArchiveList_grid" class="easyui-datagrid" style="width:100%;" title="部门档案权限 (@ViewBag.Title)" data-options="
       rownumbers:true,
       singleSelect:true,
       autoRowHeight:false,
       pagination:false,
       fitColumns:true,
       fit:false,
       striped:true,
       checkOnSelect:false,
       selectOnCheck:false,
       toolbar:'#ArchiveAuthority_DepartmentArchiveList_tb',
       collapsible:false">
    <thead frozen="true">
        <tr>
            @{foreach (var c in listColumns)
                {
                    if (c.Frozen)
                    {
                        <th field="@c.FieldValue" width="@c.Len" align="center" formatter="@c.Formate">@c.FieldText</th>
                    }

                }
            }
        </tr>
    </thead>
    <thead>
        <tr>
            @{foreach (var c in listColumns)
            {
                if (!c.Frozen)
                {
                <th field="@c.FieldValue" width="@c.Len" align="center" formatter="@c.Formate">@c.FieldText</th>
                }

            }
            }
        </tr>
        </thead>
    </table>
<div id="ArchiveAuthority_DepartmentArchiveList_tb" style="padding:2px 5px;">
    <table style="width:100%">
        <tr>
            <td>
                <a href="javascript:void(0);" id="ArchiveAuthority_DepartmentArchiveList_btnAllClose" class="easyui-linkbutton button-orange" iconCls="icon-cancel" onclick="allCheck(0)" style="width:110px;height:30px;">全部禁止</a>
                <a href="javascript:void(0);" id="ArchiveAuthority_DepartmentArchiveList_btnAllOK" class="easyui-linkbutton button-blue" iconCls="icon-ok" onclick="allCheck(1)" style="width:110px;height:30px;">全部允许</a>
                <select id="ArchiveAuthority_DepartmentArchiveList_cmbShow" class="easyui-combobox" label="显示：" labelwidth="50px" labelalign="right" style="width:115px" editable="false" panelHeight="auto">
                    <option value="-1">不变</option>
                    <option value="0">禁止</option>
                    <option value="1">允许</option>
                </select>
                <select id="ArchiveAuthority_DepartmentArchiveList_cmbView" class="easyui-combobox" label="浏览：" labelwidth="50px" labelalign="right" style="width:115px" editable="false" panelHeight="auto">
                    <option value="-1">不变</option>
                    <option value="0">禁止</option>
                    <option value="1">允许</option>
                </select>
                <select id="ArchiveAuthority_DepartmentArchiveList_cmbPrint" class="easyui-combobox" label="打印：" labelwidth="50px" labelalign="right" style="width:115px" editable="false" panelHeight="auto">
                    <option value="-1">不变</option>
                    <option value="0">禁止</option>
                    <option value="1">允许</option>
                </select>
                <select id="ArchiveAuthority_DepartmentArchiveList_cmbDown" class="easyui-combobox" label="下载：" labelwidth="50px" labelalign="right" style="width:115px" editable="false" panelHeight="auto">
                    <option value="-1">不变</option>
                    <option value="0">禁止</option>
                    <option value="1">允许</option>
                </select>
                <select id="ArchiveAuthority_DepartmentArchiveList_cmbEdit" class="easyui-combobox" label="编辑：" labelwidth="50px" labelalign="right" style="width:115px" editable="false" panelHeight="auto">
                    <option value="-1">不变</option>
                    <option value="0">禁止</option>
                    <option value="1">允许</option>
                </select>
                <select id="ArchiveAuthority_DepartmentArchiveList_cmbApp" class="easyui-combobox" label="审批：" labelwidth="50px" labelalign="right" style="width:115px" editable="false" panelHeight="auto">
                    <option value="-1">不变</option>
                    <option value="0">禁止</option>
                    <option value="1">允许</option>
                </select>
                <a href="javascript:void(0);" id="ArchiveAuthority_DepartmentArchiveList_btnConfig" class="easyui-linkbutton button-blue" iconCls="icon-ok" onclick="configCheck()" style="width:80px;height:30px;">设定</a>
            </td>
            <td align="right">
                <a href="javascript:void(0);" id="ArchiveAuthority_DepartmentArchiveList_btnSave" class="easyui-linkbutton button-blue pull-right" iconCls="icon-save" onclick="save()" style="width:110px;height:30px;">保存</a>&nbsp;&nbsp;&nbsp;
                <a href="javascript:void(0);" id="ArchiveAuthority_DepartmentArchiveList_btnAddBm" class="easyui-linkbutton button-blue pull-right" iconCls="icon-add" onclick="addBm()" style="width:110px;height:30px;">添加部门</a>
                <a href="javascript:void(0);" id="ArchiveAuthority_DepartmentArchiveList_btnModifyBm" class="easyui-linkbutton button-blue pull-right" iconCls="icon-pencil" onclick="showModifyBm()" style="width:110px;height:30px;">修改部门</a>
            </td>
        </tr>
    </table>
</div>
<div id="ArchiveAuthority_DepartmentArchiveList_winInfo" class="easyui-window" title="编辑部门" data-options="modal:true,closed:true,iconCls:'icon-save'" minimizable="false" maximizable="false" resizable="false" collapsible="false"
     style="width:400px;height:250px;padding:10px">
    <div class="easyui-layout" data-options="fit:true">
        <div data-options="region:'center'" style="padding:10px;border:0px">
            <div style="padding-bottom:10px">
                <input class="easyui-textbox" id="ArchiveAuthority_DepartmentArchiveList_txtName" label="部门名称:" labelwidth="80px" labelalign="right" style="width:100%" data-options="required:true" />
            </div>
            <div style="padding-bottom:10px">
                <select class="easyui-combobox" id="ArchiveAuthority_DepartmentArchiveList_cmbStatus" label="是否启用:" labelwidth="80px" labelalign="right" style="width:100%" editable="false" panelHeight="auto">
                    <option value="0">禁止</option>
                    <option value="1" selected="selected">启用</option>
                </select>
            </div>
        </div>
        <div data-options="region:'south',border:false" style="text-align:right;padding:0px,0,0;">
            <a class="easyui-linkbutton button-blue" data-options="iconCls:'icon-ok'" href="javascript:void(0)" style="width:100px" onclick="saveBm()" id="ArchiveAuthority_DepartmentArchiveList_btnAdd">添加</a>
            <a class="easyui-linkbutton button-blue" data-options="iconCls:'icon-ok'" href="javascript:void(0)" style="width:100px" onclick="modifyBm()" id="ArchiveAuthority_DepartmentArchiveList_btnModify">修改</a>
        </div>
    </div>
</div>
<div id="ArchiveAuthority_DepartmentArchiveList_winLine" class="easyui-window" title="编辑权限" data-options="modal:true,closed:true,iconCls:'icon-save'" minimizable="false" maximizable="false" resizable="false" collapsible="false"
     style="width:400px;height:400px;padding:10px">
    <div class="easyui-layout" data-options="fit:true">
        <div data-options="region:'center'" style="padding:10px;border:0px">
            <div style="padding-bottom:10px">
                <select class="easyui-combobox" id="ArchiveAuthority_DepartmentArchiveList_cmbShowStatus" label="允许显示:" labelwidth="80px" labelalign="right" style="width:100%" editable="false" panelHeight="auto">
                    <option value="0">禁止</option>
                    <option value="1" selected="selected">允许</option>
                </select>
            </div>
            <div style="padding-bottom:10px">
                <select class="easyui-combobox" id="ArchiveAuthority_DepartmentArchiveList_cmbViewStatus" label="浏览电子件:" labelwidth="80px" labelalign="right" style="width:100%" editable="false" panelHeight="auto">
                    <option value="0">禁止</option>
                    <option value="1" selected="selected">允许</option>
                </select>
            </div>
            <div style="padding-bottom:10px">
                <select class="easyui-combobox" id="ArchiveAuthority_DepartmentArchiveList_cmbPrintStatus" label="打印电子件:" labelwidth="80px" labelalign="right" style="width:100%" editable="false" panelHeight="auto">
                    <option value="0">禁止</option>
                    <option value="1" selected="selected">允许</option>
                </select>
            </div>
            <div style="padding-bottom:10px">
                <select class="easyui-combobox" id="ArchiveAuthority_DepartmentArchiveList_cmbDownStatus" label="下载电子件:" labelwidth="80px" labelalign="right" style="width:100%" editable="false" panelHeight="auto">
                    <option value="0">禁止</option>
                    <option value="1" selected="selected">允许</option>
                </select>
            </div>
            <div style="padding-bottom:10px">
                <select class="easyui-combobox" id="ArchiveAuthority_DepartmentArchiveList_cmbEditStatus" label="编辑信息:" labelwidth="80px" labelalign="right" style="width:100%" editable="false" panelHeight="auto">
                    <option value="0">禁止</option>
                    <option value="1" selected="selected">允许</option>
                </select>
            </div>
            <div style="padding-bottom:10px">
                <select class="easyui-combobox" id="ArchiveAuthority_DepartmentArchiveList_cmbAppStatus" label="审批借阅:" labelwidth="80px" labelalign="right" style="width:100%" editable="false" panelHeight="auto">
                    <option value="0">禁止</option>
                    <option value="1" selected="selected">允许</option>
                </select>
            </div>
        </div>
        <div data-options="region:'south',border:false" style="text-align:right;padding:0px,0,0;">
            <a class="easyui-linkbutton button-blue" data-options="iconCls:'icon-ok'" href="javascript:void(0)" style="width:100px" onclick="editOK()" >修改</a>
        </div>
    </div>
</div>
<script>
    $(document).ready(function () {
        $('#ArchiveAuthority_DepartmentArchiveList_grid').datagrid({
            url: '/ArchiveAuthority/Get_ajaxDepartmentArchiveList?DepartmentId=' + @ViewBag.DepId,
            singleSelect: true,
            method: 'post',
            onLoadSuccess: function (data) {
                $('.pagination-page-list').hide();
            }
        });
    });

    function allCheck(value) {
        //en.iApproval = en.iDown = en.iEdit = en.iPrint = en.iShow = en.iView = 0;
        var data = $('#ArchiveAuthority_DepartmentArchiveList_grid').datagrid('getData');
        var len = data.rows.length;
        for (var i = 0; i < len; i++) {
            if (data.rows[i].iEdit == -1)
                continue;
            $('#ArchiveAuthority_DepartmentArchiveList_grid').datagrid('updateRow', {
                index: i, // 此为列数
                row: {
                    iApproval: value,
                    iPrint: value,
                    iShow: value,
                    iDown: value,
                    iEdit: value,
                    iView:value
                }
            });
        }
    }

    function configCheck() {
        var v1 = $('#ArchiveAuthority_DepartmentArchiveList_cmbShow').combobox('getValue');
        var v2 = $('#ArchiveAuthority_DepartmentArchiveList_cmbView').combobox('getValue');
        var v3 = $('#ArchiveAuthority_DepartmentArchiveList_cmbPrint').combobox('getValue');
        var v4 = $('#ArchiveAuthority_DepartmentArchiveList_cmbDown').combobox('getValue');
        var v5 = $('#ArchiveAuthority_DepartmentArchiveList_cmbEdit').combobox('getValue');
        var v6 = $('#ArchiveAuthority_DepartmentArchiveList_cmbApp').combobox('getValue');

        var data = $('#ArchiveAuthority_DepartmentArchiveList_grid').datagrid('getData');
        var len = data.rows.length;
        for (var i = 0; i < len; i++) {
            if (data.rows[i].iEdit == -1)
                continue;

            if (v1 == -1)
                v1 = data.rows[i].iShow;
            if (v2 == -1)
                v2 = data.rows[i].iView;
            if (v3 == -1)
                v3 = data.rows[i].iPrint;
            if (v4 == -1)
                v4 = data.rows[i].iDown;
            if (v5 == -1)
                v5 = data.rows[i].iEdit;
            if (v6 == -1)
                v6 = data.rows[i].iApproval;

            $('#ArchiveAuthority_DepartmentArchiveList_grid').datagrid('updateRow', {
                index: i, // 此为列数
                row: {
                    iApproval: v6,
                    iPrint: v3,
                    iShow: v1,
                    iDown: v4,
                    iEdit: v5,
                    iView: v2
                }
            });
        }
    }
    
    function formatStatusI(value, row) {
        if (value == '0')
            return "<a hef='javascript:void(0);'><span style='color:red'>禁止</span></a>";
        else if (value == '1')
            return "<a hef='javascript:void(0);'><span style='color:blue'>允许</span></a>";
        else
            return "";
    }

    function formatEdit(value, row) {
        if (row['iEdit'] == -1)
            return '';
        else
            return "<a href='javascript:void(0)' onclick='edit(" + value + ")'><img src='../Content/images/pencil.png' />&nbsp;&nbsp;修改</a>";
    }

    var nowline = 0;
    function edit(value) {
        var data = $('#ArchiveAuthority_DepartmentArchiveList_grid').datagrid('getData');
        var len = data.rows.length;
        for (var i = 0; i < len; i++) {
            if (data.rows[i].iDepartmentID == value) {
                nowline = i;
                $('#ArchiveAuthority_DepartmentArchiveList_cmbShowStatus').combobox('setValue', data.rows[i].iShow);
                $('#ArchiveAuthority_DepartmentArchiveList_cmbViewStatus').combobox('setValue', data.rows[i].iView);
                $('#ArchiveAuthority_DepartmentArchiveList_cmbPrintStatus').combobox('setValue', data.rows[i].iPrint);
                $('#ArchiveAuthority_DepartmentArchiveList_cmbDownStatus').combobox('setValue', data.rows[i].iDown);
                $('#ArchiveAuthority_DepartmentArchiveList_cmbEditStatus').combobox('setValue', data.rows[i].iEdit);
                $('#ArchiveAuthority_DepartmentArchiveList_cmbAppStatus').combobox('setValue', data.rows[i].iApproval);
                break;
            }
        }
        $('#ArchiveAuthority_DepartmentArchiveList_winLine').window('open');
    }

    function editOK() {
        var v1 = $('#ArchiveAuthority_DepartmentArchiveList_cmbShowStatus').combobox('getValue');
        var v2 = $('#ArchiveAuthority_DepartmentArchiveList_cmbViewStatus').combobox('getValue');
        var v3 = $('#ArchiveAuthority_DepartmentArchiveList_cmbPrintStatus').combobox('getValue');
        var v4 = $('#ArchiveAuthority_DepartmentArchiveList_cmbDownStatus').combobox('getValue');
        var v5 = $('#ArchiveAuthority_DepartmentArchiveList_cmbEditStatus').combobox('getValue');
        var v6 = $('#ArchiveAuthority_DepartmentArchiveList_cmbAppStatus').combobox('getValue');

        $('#ArchiveAuthority_DepartmentArchiveList_grid').datagrid('updateRow', {
            index: nowline,
            row: {
                iApproval: v6,
                iPrint: v3,
                iShow: v1,
                iDown: v4,
                iEdit: v5,
                iView: v2
            }
        });
        $('#ArchiveAuthority_DepartmentArchiveList_winLine').window('close');
    }

    function save()
    {
        var data = $('#ArchiveAuthority_DepartmentArchiveList_grid').datagrid('getData');
        $.messager.confirm('提示', '确认要保存部门权限设定吗', function (r)
        {
            if (r)
            {
                $.ajax({
                    url: "/ArchiveAuthority/Save_ajaxDepartmentArchive",
                    data: { data: JSON.stringify(data.rows), departmentid: @ViewBag.DepId },
                    dataType: "text",
                    type: "post",
                    success: function (value) {
                        if (value == "1")
                            $.messager.alert('提示', '保存成功!', 'info');
                        else
                            $.messager.alert('提示', '保存失败!', 'error')
                    }
                })
             }
        })
    }


    function addBm() {
        document.getElementById('ArchiveAuthority_DepartmentArchiveList_btnAdd').style.display = '';
        document.getElementById('ArchiveAuthority_DepartmentArchiveList_btnModify').style.display = 'none';
        $('#ArchiveAuthority_DepartmentArchiveList_txtName').textbox('setValue', '');
        $('#ArchiveAuthority_DepartmentArchiveList_cmbStatus').combobox('setValue', 1);
        $('#ArchiveAuthority_DepartmentArchiveList_winInfo').window('open');
    }

    function showModifyBm() {
        $.ajax({
            method: "post",
            dataType: "json",
            url: "/ArchiveAuthority/Get_ajaxDepartment",
            data: { id:  @ViewBag.DepId },
            success: function (data) {
                document.getElementById('ArchiveAuthority_DepartmentArchiveList_btnAdd').style.display = 'none';
                document.getElementById('ArchiveAuthority_DepartmentArchiveList_btnModify').style.display = '';
                $('#ArchiveAuthority_DepartmentArchiveList_txtName').textbox('setValue', data.en.Dep_Name);
                $('#ArchiveAuthority_DepartmentArchiveList_cmbStatus').combobox('setValue', data.en.Dep_Status);
                $('#ArchiveAuthority_DepartmentArchiveList_winInfo').window('open');
            }
        })
    }

    function saveBm() {
        var name = $('#ArchiveAuthority_DepartmentArchiveList_txtName').val();
        var status = $('#ArchiveAuthority_DepartmentArchiveList_cmbStatus').combobox('getValue');

        if (name == '') {
            $.messager.alert('提示', '必须输入部门名称!', 'error');
            return;
        }
        $.ajax({
            method: "post",
            dataType: "text",
            url: "/ArchiveAuthority/Add_ajaxDepartment",
            data: { name: name, status: status },
            success: function (data) {
                //alert(data);
                if (data == '-1')
                    $.messager.alert('提示', '保存失败!', 'error');
                else if (data == '0')
                    $.messager.alert('提示', '重复的部门名称', 'error');
                else {
                    ///刷新主页面
                    window.parent.location.reload();
                }
            }
        })
    }


    function modifyBm() {
        var name = $('#ArchiveAuthority_DepartmentArchiveList_txtName').val();
        var status = $('#ArchiveAuthority_DepartmentArchiveList_cmbStatus').combobox('getValue');

        $.ajax({
            method: "post",
            dataType: "text",
            url: "/ArchiveAuthority/Modify_ajaxDepartment",
            data: {id: @ViewBag.DepId, name: name, status: status },
            success: function (data) {
                if (data == '-1')
                    $.messager.alert('提示', '保存失败!', 'error');
                else if (data == '0')
                    $.messager.alert('提示', '重复的部门名称', 'error');
                else {
                    ///刷新主页面
                    window.parent.location.reload();
                }
            }
        })
    }
</script>